using System;
using Microsoft.SharePoint;

namespace SharePoint.DataMapper
{
	[FieldMapper(typeof(SPFieldMultiLineText), SPFieldType.Note)]
	public class FieldNoteMapper : FieldMapper
	{
		protected override SPField AddFieldInternal(ListDataContext context, SPFieldCollection collection, Type propertyType, FieldAttribute attribute)
		{
			SPFieldMultiLineText field = (SPFieldMultiLineText)base.AddFieldInternal(context, collection, propertyType, attribute);
			field.NumberOfLines = attribute.NumberOfLines;
			field.RichText = attribute.RichText;
			field.RestrictedMode = attribute.RichTextRestrictedMode;
			field.RichTextMode = attribute.RichTextMode;
			field.AppendOnly = attribute.AppendOnly;
			return field;
		}

		protected override FieldAttribute GetFieldAttributeInternal(SPField field)
		{
			FieldAttribute attribute = base.GetFieldAttributeInternal(field);
			
			SPFieldMultiLineText fieldMultiLineText = field as SPFieldMultiLineText;
			if (fieldMultiLineText == null)
			{
				return attribute;
			}
			attribute.NumberOfLines = fieldMultiLineText.NumberOfLines;
			attribute.RichText = fieldMultiLineText.RichText;
			attribute.RichTextRestrictedMode = fieldMultiLineText.RestrictedMode;
			attribute.RichTextMode = fieldMultiLineText.RichTextMode;
			attribute.AppendOnly = fieldMultiLineText.AppendOnly;
			return attribute;
		}
	}
}